<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px">
      <el-form-item label="报名序号" prop="registrationId">
        <el-input
          v-model="queryParams.registrationId"
          placeholder="请输入报名序号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生源地市" prop="nativeCity">
        <el-input
          v-model="queryParams.nativeCity"
          placeholder="请输入生源地市"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="准考证号(纸笔)" prop="writtenExamNo">
        <el-input
          v-model="queryParams.writtenExamNo"
          placeholder="请输入准考证号(纸笔)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="准考证号(机考)" prop="computerExamNo">
        <el-input
          v-model="queryParams.computerExamNo"
          placeholder="请输入准考证号(机考)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资格审查结果" prop="qualificationReview">
        <el-select v-model="queryParams.qualificationReview" placeholder="请选择资格审查结果" clearable>
          <el-option
            v-for="dict in sulectList"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!--      <el-form-item>-->
      <!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
      <!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      <!--      </el-form-item>-->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
<!--      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:qualification:add']"
        >新增</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:qualification:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['system:qualification:import']"
        >导入</el-button>
      </el-col>
<!--      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleImportTemplate"
          v-hasPermi="['system:qualification:import']"
        >下载模板</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-view"
          size="mini"
          @click="clickIdCard"
        >识别</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-check"
          size="mini"
          :disabled="multiple"
          @click="handleBatchPass"
          v-hasPermi="['system:qualification:edit']"
        >批量资格审查通过</el-button>
      </el-col>
      <!-- 新增全选按钮 -->
<!--      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-check"
          size="mini"
          @click="toggleAllSelection"
        >全选</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="qualificationList" @selection-change="handleSelectionChange" ref="qualificationTable">
      <el-table-column type="selection" width="55" align="center" />
<!--            <el-table-column label="自增主键" align="center" prop="id" />-->
      <el-table-column label="报名序号" align="center" prop="registrationId" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="身份证号" align="center" prop="idCard" />
      <el-table-column label="性别" align="center" prop="gender" />
      <el-table-column label="生源地市" align="center" prop="nativeCity" />
      <el-table-column label="准考证号(纸笔)" align="center" prop="writtenExamNo" />
      <el-table-column label="准考证号(机考)" align="center" prop="computerExamNo" />
      <el-table-column label="行测成绩" align="center" prop="administrativeScore" />
      <el-table-column label="申论成绩" align="center" prop="essayScore" />
      <el-table-column label="专业科目成绩" align="center" prop="professionalScore" />
      <el-table-column label="总成绩" align="center" prop="totalScore" />
      <el-table-column label="合成分数" align="center" prop="compositeScore" />
      <el-table-column label="面试成绩" align="center" prop="interviewScore" />
      <el-table-column label="标记" align="center" prop="remark" />
      <el-table-column label="行测缺考" align="center" prop="administrativeAbsent" />
      <el-table-column label="申论缺考" align="center" prop="essayAbsent" />
      <el-table-column label="专业科目缺考" align="center" prop="professionalAbsent" />
      <el-table-column label="政治面貌" align="center" prop="politicalStatus" />
      <el-table-column label="最高学历" align="center" prop="highestDegree" />
      <el-table-column label="学位" align="center" prop="academicDegree" />
      <el-table-column label="毕业院校" align="center" prop="graduateSchool" />
      <el-table-column label="院系" align="center" prop="department" />
      <el-table-column label="专业" align="center" prop="major" />
      <el-table-column label="手机号码" align="center" prop="phoneNumber" />
      <el-table-column label="资格审查结果" align="center" prop="qualificationReview">
        <template slot-scope="scope">
          <el-tag :type="scope.row.qualificationReview == '未通过' ? 'danger' : 'success'">{{scope.row.qualificationReview}}</el-tag>
          <!--          <dict-tag :options="dict.type.sys_qualification_status" :value="scope.row.qualificationReview"/>-->
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:qualification:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:qualification:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改警校考生资格审查信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-alert
          title="提示：当资格审查结果设置为 通过 时，考生信息将自动流转到体能测评模块"
          type="info"
          :closable="false"
          style="margin-bottom: 15px;"
        />
        <el-row>
          <el-col :span="12">
            <el-form-item label="报名序号" prop="registrationId">
              <el-input v-model="form.registrationId" placeholder="请输入报名序号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="身份证号" prop="idCard">
              <el-input v-model="form.idCard" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="gender">
              <el-input v-model="form.gender" placeholder="请输入性别" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生源地市" prop="nativeCity">
              <el-input v-model="form.nativeCity" placeholder="请输入生源地市" />
            </el-form-item>
          </el-col>
          <!--          <el-col :span="12">
                      <el-form-item label="准考证号(纸笔)" prop="writtenExamNo">
                        <el-input v-model="form.writtenExamNo" placeholder="请输入准考证号(纸笔)" />
                      </el-form-item>
                    </el-col>-->
          <!--          <el-col :span="12">
                      <el-form-item label="准考证号(机考)" prop="computerExamNo">
                        <el-input v-model="form.computerExamNo" placeholder="请输入准考证号(机考)" />
                      </el-form-item>
                    </el-col>-->
          <!--          <el-col :span="12">
                      <el-form-item label="行测成绩" prop="administrativeScore">
                        <el-input v-model="form.administrativeScore" placeholder="请输入行测成绩" />
                      </el-form-item>
                    </el-col>-->
          <!--          <el-col :span="12">
                      <el-form-item label="申论成绩" prop="essayScore">
                        <el-input v-model="form.essayScore" placeholder="请输入申论成绩" />
                      </el-form-item>
                    </el-col>-->
          <!--          <el-col :span="12">
                      <el-form-item label="专业科目成绩" prop="professionalScore">
                        <el-input v-model="form.professionalScore" placeholder="请输入专业科目成绩" />
                      </el-form-item>
                    </el-col>-->
          <!--          <el-col :span="12">
                      <el-form-item label="总成绩" prop="totalScore">
                        <el-input v-model="form.totalScore" placeholder="请输入总成绩" />
                      </el-form-item>
                    </el-col>-->
          <!--          <el-col :span="12">
                      <el-form-item label="合成分数" prop="compositeScore">
                        <el-input v-model="form.compositeScore" placeholder="请输入合成分数" />
                      </el-form-item>
                    </el-col>-->
          <!--          <el-col :span="12">
                      <el-form-item label="面试成绩" prop="interviewScore">
                        <el-input v-model="form.interviewScore" placeholder="请输入面试成绩" />
                      </el-form-item>
                    </el-col>-->
          <!--          <el-col :span="12">
                      <el-form-item label="标记" prop="remark">
                        <el-input v-model="form.remark" placeholder="请输入标记" />
                      </el-form-item>
                    </el-col>-->
          <!--          <el-col :span="12">
                      <el-form-item label="行测缺考" prop="administrativeAbsent">
                        <el-input v-model="form.administrativeAbsent" placeholder="请输入行测缺考" />
                      </el-form-item>
                    </el-col>-->
          <!--          <el-col :span="12">
                      <el-form-item label="申论缺考" prop="essayAbsent">
                        <el-input v-model="form.essayAbsent" placeholder="请输入申论缺考" />
                      </el-form-item>
                    </el-col>-->
          <!--          <el-col :span="12">
                      <el-form-item label="专业科目缺考" prop="professionalAbsent">
                        <el-input v-model="form.professionalAbsent" placeholder="请输入专业科目缺考" />
                      </el-form-item>
                    </el-col>-->
          <el-col :span="12">
            <el-form-item label="最高学历" prop="highestDegree">
              <el-input v-model="form.highestDegree" placeholder="请输入最高学历" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="学位" prop="academicDegree">
              <el-input v-model="form.academicDegree" placeholder="请输入学位" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="毕业院校" prop="graduateSchool">
              <el-input v-model="form.graduateSchool" placeholder="请输入毕业院校" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="院系" prop="department">
              <el-input v-model="form.department" placeholder="请输入院系" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="专业" prop="major">
              <el-input v-model="form.major" placeholder="请输入专业" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="phoneNumber">
              <el-input v-model="form.phoneNumber" placeholder="请输入手机号码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="编号" prop="registrationId">
              <el-input v-model="form.bianhao" placeholder="请输入编号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考生照片" prop="photoPath">
              <div v-if="form.idCard">
                <img :src="photoUrl + form.idCard + '.jpg'" style="vertical-align: bottom; width: 100px; height: 140px;" />
<!--                <el-button style="margin-left:20px" type="danger" @click="deletephoto()">删除</el-button>-->
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="资格审查结果" prop="qualificationReview">
              <el-radio v-model="form.qualificationReview" label="通过">通过</el-radio>
              <el-radio v-model="form.qualificationReview" label="未通过">未通过</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定 并 打 印</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的数据
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：如果数据已存在，将根据身份证号或报名序号更新数据</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>


    <div style="display: none">
      <div id="prints">
        <div>
          <div style="padding: 20px 0 0 0;font-weight: 600;">
            <div style="margin-bottom: 20px;">编号：{{printContent.count}}</div>
            <div style="margin: auto;">
              <div style="text-align: center;font-size: 26px">{{printContent.content}}</div>
              <div style="text-align: center;margin-top: 12px;font-size: 24px">体能测评表</div>
            </div>
          </div>
          <div style="border: 3px solid #000;margin-top: 10px;">
            <div style="border-top: 1px solid #000;height: 49mm;display: flex;width: 100%;">
              <div style="width: calc(100% - 35mm);height: 100%;">
                <div style="display: flex;width: 100%;height:25mm;line-height: 25mm;">
                  <div style="width: 30%;border-right: 1px solid #000;text-align: center;">
                    <span>考生编号</span>
                  </div>
                  <div style="border-right: 1px solid #000;text-align: center;width: 70%;">
                    <span>{{form.bianhao}}</span>
                  </div>
                </div>
                <div style="display: flex;width: 100%;height:24mm;line-height: 24mm">
                  <div style="width: 30%;background-color: #e6e6e6;border-right: 1px solid #000;"
                       v-if="datebirth > 30">
                    <div class="title-namea">年龄（周岁）</div>
                  </div>
                  <div style="width: 30%;border-right: 1px solid #000;"
                       v-if="datebirth < 30 || datebirth == 30">
                    <div class="title-namea">年龄（周岁）</div>
                  </div>
                  <div style="width:20%;">
                    <div class="title-namea">{{ datebirth }}</div>
                  </div>
                  <div
                    style="width: 30%;background-color: #e6e6e6;border-right: 1px solid #000;border-left: 1px solid #000;"
                    v-if="datebirth > 30">
                    <div class="title-namea">性别</div>
                  </div>
                  <div style="width: 30%;border-right: 1px solid #000;border-left: 1px solid #000;"
                       v-if="datebirth < 30 || datebirth == 30">
                    <div class="title-namea">性别</div>
                  </div>
                  <div style="width: 20%;border-right: 1px solid #000;">
                    <div class="title-namea">{{ this.form.gender }}</div>
                  </div>
                </div>
              </div>

              <div style="width: 35mm;">
                <img :src="photoUrl + form.idCard + '.jpg'"  @error="handleImageError" style="width: 34mm;height: 48mm;margin: 2px 0 0 2px;"
                     />
              </div>
            </div>


            <div style="display: flex;text-align: center;">
              <div style="border-right: 1px solid #000;width: calc((100% - 35mm) * 0.3)">
                <div class="title-name">体能测评标准</div>
              </div>
              <div style="width: calc(100% - (100% - 35mm) * 0.3);">
                <div class="title-name">
                  <span v-if="datebirth < 31 && this.form.gender == '男'">
                    <span>纵跳摸高≥265厘米；10米×4往返跑≤13″1 ；1000米跑≤4′25″</span>
                  </span>
                  <span v-if="datebirth >= 31 && this.form.gender == '男'">
                    <span>纵跳摸高≥265厘米；10米×4往返跑≤13″4；1000米跑≤4′35″</span>
                  </span>
                  <span v-if="datebirth < 31 && this.form.gender == '女'">
                    <span>纵跳摸高≥230厘米；10米×4往返跑≤14″1；800米跑≤4′20″</span>
                  </span>
                  <span v-if="datebirth >= 31 && this.form.gender == '女'">
                    <span>纵跳摸高≥230厘米；10米×4往返跑≤14″4；800米跑≤4′30″</span>
                  </span>
                </div>
              </div>
            </div>

            <div style="display: flex;border-top: 1px solid #000;padding-left: 10px;
            height: 60px;line-height: 60px;font-weight: 600;font-size: 18px;">
              <div style="width: 40%;">资格审查结果登记：</div>
              <div style="width: 30%;">初审人：</div>
              <div style="width: 30%;">复审人：</div>
            </div>

            <div style="display: flex;font-size: 18px">
              <div style="width: 40%;">
                <div class="title-names">体能测评</div>
              </div>
              <div class="title-left" style="width: calc(20% - 1px);">
                <div class="title-names">成绩</div>
              </div>
              <div class="title-left" style="width: 20%;">
                <div class="title-names">裁判员签字</div>
              </div>
              <div class="title-left" style="width: 20%;">
                <div class="title-names">监督员签字</div>
              </div>
            </div>

            <div style="display: flex;">
              <div style="width: 10%;">
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">1</div>
                <div class="title-name">2</div>
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">3</div>
                <div class="title-name">4</div>
                <div>
                  <div class="title-name"
                       style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">5</div>
                  <div class="title-name">6</div>
                </div>
              </div>
              <div class="title-left" style="width: 30%;">
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">男子纵跳摸高</div>
                <div class="title-name">女子纵跳摸高</div>
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">男子10米×4往返跑
                </div>
                <div class="title-name">女子10米×4往返跑</div>
                <div>
                  <div class="title-name"
                       style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">男子1000米跑</div>
                  <div class="title-name">女子800米跑</div>
                </div>
              </div>
              <div class="title-left" style="width: calc(20% - 1px);">
                <div class="title-name"
                     style="padding:0 5px 0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                <div class="title-name"></div>
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact"></div>
                <div class="title-name"></div>
                <div>
<!--                  v-if="shenfenList.supplementphysicalfitnesstest==null || !shenfenList.supplementphysicalfitnesstest.includes('技术类')">-->
                  <div class="title-name"
                       style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                  <div class="title-name"></div>
                </div>
<!--                <div v-else>
                  <div class="title-name"
                       style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;">
                    <img src="@/assets/images/免测.png" style="width: 40px;" />
                  </div>
                  <div class="title-name">
                    <img src="@/assets/images/免测.png" style="width: 40px;" />
                  </div>
                </div>-->
              </div>
              <div class="title-left" style="width: 20%;">
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                <div class="title-name"></div>
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                <div class="title-name"></div>
                <div>
                  <div class="title-name"
                       style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                  <div class="title-name"></div>
                </div>
              </div>
              <div class="title-left" style="width: 20%">
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                <div class="title-name"></div>
                <div class="title-name"
                     style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                <div class="title-name"></div>
                <div>
                  <div class="title-name"
                       style="padding:0 2px;background-color: #e6e6e6;-webkit-print-color-adjust: exact;"></div>
                  <div class="title-name"></div>
                </div>
              </div>
            </div>

            <div style="display: flex;border-top: 1px solid #000;padding-left: 10px;
            height: 90px;font-weight: 600;font-size: 18px;">
              <div style="width: 35%;border-right: 1px solid #000;">
                <div style="margin-top: 20px">体能测评</div>
                <div style="margin-top: 5px">结果登记</div>
              </div>
              <div style="width: calc(25% - 2px);border-right: 1px solid #000;line-height: 90px;margin-left: 10px">裁判长：</div>
              <div style="width: calc(40% + 2px);margin-left: 10px">
                <div style="margin-top: 20px;">考生签字确认：</div>
                <div style="margin-top: 5px">身份证号：</div>
              </div>
            </div>
          </div>

          <div style="margin: 5px 0px;font-size: 17px;">
            <div class="text">注：</div>
            <div class="text">男子30岁(含)以下测评标准：纵跳摸高≥265厘米；10米×4往返跑≤13″1；1000米跑≤4′25″；</div>
            <div class="text">男子31岁(含)以上测评标准：纵跳摸高≥265厘米；10米×4往返跑≤13″4；1000米跑≤4′35″；</div>
            <div class="text">女子30岁(含)以下测评标准：纵跳摸高≥230厘米；10米×4往返跑≤14″1；800米跑≤4′20″；</div>
            <div class="text">女子31岁(含)以上测评标准：纵跳摸高≥230厘米；10米×4往返跑≤14″4；800米跑≤4′30″；</div>
            <div class="text">年龄计算时间截止到参加体能测评当月。</div>
            <!--            <div class="text">警务技术职位测查10米×4往返跑和纵跳摸高项目，其它职位测查全部3个项目。</div>-->
            <div class="text">未达到测评标准，不合格。</div>
            <div style="float: right;margin-top: -10px;margin-right: 10px;">
              <img style="width: 180px;height: 60px;" :src="barcodeUrl + form.idCard + '.png'" @error="handleImageError"/>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";
import {
  listQualification,
  getQualification,
  delQualification,
  addQualification,
  updateQualification,
  getPrint,
  batchPassQualification,
  findRiQi
} from "@/api/system/qualification";
import { getToken } from "@/utils/auth";
import {listMedical} from "@/api/system/medical";
import printJS from "print-js";


export default {
  name: "Qualification",
  dicts: ['sys_qualification_status'],
  data() {
    return {
      datebirth:"",
      photoUrl: process.env.VUE_APP_BASE_API + "/profile/",
      barcodeUrl: process.env.VUE_APP_BASE_API + "/profile/barcode/",
      printContent:{},
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 警校考生资格审查信息表格数据
      qualificationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        registrationId: null,
        name: null,
        idCard: null,
        nativeCity: null,
        writtenExamNo: null,
        computerExamNo: null,
        phoneNumber: null,
        qualificationReview: null
      },
      // 表单参数
      form: {
        bianhao: null,
        registrationId: null, // 添加编号字段
        photoPath: null // 添加照片路径字段
      },
      sulectList: [{
        value: '通过',
        label: '通过'
      }, {
        value: '未通过',
        label: '未通过'
      }],
      // 表单校验
      rules: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        idCard: [
          { required: true, message: "身份证号不能为空", trigger: "blur" }
        ],
      },
      // 导入参数
      upload: {
        // 是否显示导入对话框
        open: false,
        // 导入对话框标题
        title: "导入警校考生资格审查信息",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的数据
        updateSupport: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/qualification/importData"
      },
      selectedRows: [], // 新增字段，用于存储选中的行数据
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleImageError(e) {
      // 设置一个空白图片作为替代，而不是隐藏元素
      e.target.src = '';
    },
    clickIdCard() {
      axios.get('http://127.0.0.1:19196/readcard')
        .then((res) => {
          let idCard = res.data.certNumber
          this.queryParams.pageNum = 1;
          this.queryParams.idCard = idCard;
          this.loading = true;
          listQualification(this.queryParams).then(response => {
            this.qualificationList = response.rows;
            this.total = response.total;
            this.loading = false;
            // 检查结果数量是否为1，如果是则弹出修改窗口
            if (this.qualificationList.length === 1) {
              this.handleUpdate(this.qualificationList[0]);
            }else{
              this.$message.error('未查询到此人');
            }
            this.queryParams = {}
            this.getList()
          });
        })
    },
    /** 查询警校考生资格审查信息列表 */
    getList() {
      this.loading = true;
      listQualification(this.queryParams).then(response => {
        this.qualificationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        registrationId: null,
        name: null,
        idCard: null,
        gender: null,
        nativeCity: null,
        writtenExamNo: null,
        computerExamNo: null,
        administrativeScore: null,
        essayScore: null,
        professionalScore: null,
        totalScore: null,
        compositeScore: null,
        interviewScore: null,
        administrativeAbsent: null,
        essayAbsent: null,
        professionalAbsent: null,
        politicalStatus: null,
        highestDegree: null,
        academicDegree: null,
        graduateSchool: null,
        department: null,
        major: null,
        phoneNumber: null,
        qualificationReview: null,
        remark: null,
        photoPath: null // 重置照片路径
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.selectedRows = selection; // 更新选中的行数据
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加警校考生资格审查信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      findRiQi().then(response => {
        this.riqi = response.data;
      })
      this.reset();
      const id = row.id || this.ids
      getQualification(id).then(response => {
        this.form = response.data;
        this.form.photoPath = response.data.photoPath; // 设置照片路径

        // 计算年龄
        const idCard = response.data.idCard;
        if (idCard) {
          const birthYear = parseInt(idCard.substring(6, 10));
          const birthMonth = parseInt(idCard.substring(10, 12));
          const birthDay = parseInt(idCard.substring(12, 14));
          const birthDate = new Date(birthYear, birthMonth, birthDay);

          setTimeout(() => {

            if (this.riqi) {
              const targetDate = new Date(this.riqi.nian, this.riqi.yue, this.riqi.ri); // 2025年3月31日
              console.log(targetDate,'targetDate')
              let age = targetDate.getFullYear() - birthDate.getFullYear();
              const monthDiff = targetDate.getMonth() - birthDate.getMonth();
              if (monthDiff < 0 || (monthDiff === 0 && targetDate.getDate() < birthDate.getDate())) {
                age--;
              }
              this.datebirth = age;
            }
          },100)
        }

        this.open = true;
        this.title = "修改警校考生资格审查信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          // 添加资格审查结果的验证逻辑
          if (!this.form.qualificationReview) {
            this.$modal.msgError("请录入资格审查结果再保存打印");
            return;
          }

          // 禁止重复保存打印
          // if (this.form.id != null && this.form.qualificationReview) {
          //   this.$modal.msgError("已经保存过资格审查结果，不能再次保存打印");
          //   return;
          // }

          if (this.form.id != null) {
            updateQualification(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              // this.getList();
              getPrint().then(response => {
                  this.printContent = response.data;
                  setTimeout(() => {
                    this.print()
                  },100)
              })
            });
          } else {
            addQualification(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除警校考生资格审查信息编号为"' + ids + '"的数据项？').then(function() {
        return delQualification(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/qualification/export', {
        ...this.queryParams
      }, `qualification_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "警校考生资格审查信息导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    handleImportTemplate() {
      this.download('/system/qualification/importTemplate', {}, `警校考生资格审查信息_导入模板.xlsx`);
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 删除照片
    deletephoto() {
      // 这里可以添加删除照片的逻辑，比如调用后端API删除照片
      // this.form.photoPath = null; // 清空照片路径
      this.$message.success("照片已删除");
    },

    print() {
      const style = '@page {margin:0 10mm;}'
      printJS({
        //  设置打印区域id
        printable: "prints",
        type: "html",
        // header: '标题',
        // headerStyle: 'text-align:center; font-size: 24px; font-weight: bold; color: blue;', // 标题样式
        // targetStyles: ["*"],
        targetStyles: ["*", "#title"],
        style: style,
      });
    },

    // 新增方法，处理批量通过逻辑
    handleBatchPass() {
      if (this.selectedRows.length === 0) {
        this.$modal.msgWarning("请先选择需要通过的记录");
        return;
      }

      this.$modal.confirm('是否确认将选中的记录资格审查结果批量设置为通过？').then(() => {
        // 设置选中的记录的资格审查结果为“通过”
        const updatedRows = this.selectedRows.map(row => ({
          ...row,
          qualificationReview: '通过'
        }));

        batchPassQualification(updatedRows).then(response => {
          this.$modal.msgSuccess("批量通过成功");
          this.getList();
        }).catch(() => {});
      }).catch(() => {});
    },

    // 新增方法，用于全选表格中的所有行
    toggleAllSelection() {
      this.$refs.qualificationTable.toggleAllSelection();
    },
  }
};
</script>


<style>

/* 在样式表中设置无边框样式 */
.no-border-input .el-input__inner {
  border: none;
  border-radius: 0;
}

.dashboard-buttonWhite {
  min-width: 80px;
  color: #fff;
  background-color: #2eb4bd;
  border: 1px solid #2eb4bd;
  font-size: 14px;
  padding: 8px;
  border-radius: 5px;
}

/deep/ .title {
  font-size: 50px !important;
}

.titlename {
  border-top: 1px solid #000;
  line-height: 45px;
  height: 45px;
  font-size: 18px;
  text-align: center;
}

.title-name {
  border-top: 1px solid #000;
  line-height: 40px;
  height: 40px;
  font-size: 18px;
  text-align: center;
}

.title-namea {
  border-top: 1px solid #000;
  font-size: 18px;
  text-align: center;
}

.title-names {
  border-top: 1px solid #000;
  line-height: 45px;
  height: 45px;
  text-align: center;
  font-weight: 600;
  font-size: 20px;
}

.title-left {
  border-left: 1px solid #000;
}

.text {
  padding: 2px;
  line-height: 25px;
}
</style>

